<?php
if (!defined('INDEX')) exit;
require("common/functions_jcas_modules.php");
?>
<table width="100%"  border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td class="datatd" bgcolor="#FFFFFF"><?php echo $lang['database_desc']?></td>
  </tr>
</table>
<br />
<?php
####### ACTIONS ########

// Repair table
echo database_repair_table();
// Optimize_table
echo database_optimize_table();

if($show_content)
{

switch(@$_GET["p"])
{
	case "show":
	default:
		// Get table size
			$q_table_size = $DB->query("SHOW TABLE STATUS");
			$num_table_size = $DB->num_rows($q_table_size);
		?>

		<table width="100%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
		<form name="frm_show" method="post" action="<?php echo $index_url?>&p=show">
			<tr>
				<td colspan="20" class="headtd"><?php echo $lang["databases_title"]?></td>
			</tr>
			<tr align="center">
				<td width="30"  class="subheadtd"><?php echo $lang['order']?></td>
				<td class="subheadtd"><?php echo $lang['database_name']?></td>
				<td class="subheadtd"><?php echo $lang['records']?></td>
				<td class="subheadtd"><?php echo $lang['size']?></td>
				<td class="subheadtd"><?php echo $lang['check_msg']?></td>
				<td width="80" class="subheadtd"><?php echo $lang['action']?></td>
			</tr>
			<?php
			$db_size = 0;
			$db_records = 0;
			$no = 0;
			for($x=0;$x<$num_table_size;$x++)
			{
				$no += 1;
				$table = $DB->result_array($q_table_size,$x,"Name,Rows,data_length,index_length");
				$tbl_size[$table['Name']] = $table['data_length'] + $table['index_length'];
				$db_size += $tbl_size[$table['Name']];
				$db_records += $table['Rows'];
				$q_tbl_check = $DB->query('CHECK TABLE '.$table['Name']);
				$tbl_status = $DB->fetch_assoc($q_tbl_check);
			?> 
					<tr onMouseOver="rollon(this);" onMouseOut="rolloff(this);">
						<td align="right" class="datatd" ><?php echo $no?></td>
						<td align="left" class="datatd" ><strong><?php echo $table['Name']?></strong></td>
						<td align="right" class="datatd"><font color="blue"><?php echo number_format($table['Rows'])?> records</font> </td>
						<td align="right" class="datatd"><?php echo number_format($tbl_size[$table['Name']]/(1024*1024),2)?> MB</td>
						<td align="left" class="datatd" ><font color="red"><?php echo $tbl_status['Msg_type'].'='.$tbl_status['Msg_text']?></font></td>
						<td align="center" class="datatd">
						<a href="<?php echo $index_url?>&repair=<?php echo $table['Name']?>" title="<?php echo $lang['repair_this_table']?>"><img src="images/icon/icon_repair.gif" width="17" height="17" /></a>
						&nbsp;
						<a href="<?php echo $index_url?>&optimize=<?php echo $table['Name']?>" title="<?php echo $lang['optimize_this_table']?>"><img src="images/icon/icon_optimize.gif" width="17" height="17" /></a>
						</td>
					  </tr><?php
			}
			?>
					  <tr height="22">
						 <td align="center" class="row1td" >&nbsp;</td>
						 <td align="right" class="row1td"><strong><?php echo $lang['total']?></strong> :</td>
						 <td align="right" class="row1td"><strong><?php echo number_format($db_records)?></strong> records</td>
						 <td align="right" class="row1td"><strong><?php echo number_format($db_size/(1024*1024),2)?></strong> MB</td>
						 <td align="left" class="row1td" >&nbsp;</td>
						 <td align="left" class="row1td">&nbsp;</td>
					  </tr>
			  </form>
			</table>
		<?php
		break;
}// end switch
}// end show_content
$_GET["p"] = false;
?>